package cn.iocoder.yudao.module.social.dal.mysql.interaction;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.social.controller.admin.interaction.vo.InteractionPageReqVO;
import cn.iocoder.yudao.module.social.dal.dataobject.interaction.InteractionDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 互动 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface InteractionMapper extends BaseMapperX<InteractionDO> {

    default PageResult<InteractionDO> selectPage(InteractionPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InteractionDO>()
                .eqIfPresent(InteractionDO::getContentId, reqVO.getContentId())
                .eqIfPresent(InteractionDO::getUserId, reqVO.getUserId())
                .eqIfPresent(InteractionDO::getType, reqVO.getType())
                .eqIfPresent(InteractionDO::getParentId, reqVO.getParentId())
                .betweenIfPresent(InteractionDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InteractionDO::getId));
    }

    default List<InteractionDO> selectListByContentId(Long contentId) {
        return selectList(new LambdaQueryWrapperX<InteractionDO>()
                .eq(InteractionDO::getContentId, contentId)
                .orderByDesc(InteractionDO::getCreateTime));
    }

    default List<InteractionDO> selectListByUserId(Long userId) {
        return selectList(new LambdaQueryWrapperX<InteractionDO>()
                .eq(InteractionDO::getUserId, userId)
                .orderByDesc(InteractionDO::getCreateTime));
    }

    default List<InteractionDO> selectListByType(String type) {
        return selectList(new LambdaQueryWrapperX<InteractionDO>()
                .eq(InteractionDO::getType, type)
                .orderByDesc(InteractionDO::getCreateTime));
    }

    default List<InteractionDO> selectListByParentId(Long parentId) {
        return selectList(new LambdaQueryWrapperX<InteractionDO>()
                .eq(InteractionDO::getParentId, parentId)
                .orderByDesc(InteractionDO::getCreateTime));
    }

    default List<InteractionDO> selectListByContentIdAndType(Long contentId, String type) {
        return selectList(new LambdaQueryWrapperX<InteractionDO>()
                .eq(InteractionDO::getContentId, contentId)
                .eq(InteractionDO::getType, type)
                .orderByDesc(InteractionDO::getCreateTime));
    }

    default InteractionDO selectByContentIdAndUserIdAndType(Long contentId, Long userId, String type) {
        return selectOne(new LambdaQueryWrapperX<InteractionDO>()
                .eq(InteractionDO::getContentId, contentId)
                .eq(InteractionDO::getUserId, userId)
                .eq(InteractionDO::getType, type));
    }

    default Long selectCountByContentId(Long contentId) {
        return selectCount(new LambdaQueryWrapperX<InteractionDO>()
                .eq(InteractionDO::getContentId, contentId));
    }

    default Long selectCountByContentIdAndType(Long contentId, String type) {
        return selectCount(new LambdaQueryWrapperX<InteractionDO>()
                .eq(InteractionDO::getContentId, contentId)
                .eq(InteractionDO::getType, type));
    }

    default Long selectCountByUserId(Long userId) {
        return selectCount(new LambdaQueryWrapperX<InteractionDO>()
                .eq(InteractionDO::getUserId, userId));
    }

}
